package com.LostAndFound.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.LostAndFound.domain.Root;
import com.LostAndFound.service.PersonalService;

public class personalServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	PersonalService service = new PersonalService();
	
	public void handleUpdatePersonalInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取表单的值
		Integer rid = Integer.parseInt(request.getParameter("rid"));
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		Integer gender = Integer.parseInt(request.getParameter("gender"));
		String cellphone = request.getParameter("cellphone");
		String email = request.getParameter("email");
		String realname = request.getParameter("realname");
		String resume = request.getParameter("resume");
		//封装
		Root newRoot = new Root();
		newRoot.setRid(rid);
		newRoot.setUsername(username);
		newRoot.setPassword(password);
		newRoot.setGender(gender);
		newRoot.setCellphone(cellphone);
		newRoot.setEmail(email);
		newRoot.setRealname(realname);
		newRoot.setResume(resume);
		//判断是否更新成功
		boolean isSuccess = false;
		isSuccess = service.handleUpdatePersonalInfo(newRoot);
		if(isSuccess){
			//成功则更新session的root
			HttpSession session = request.getSession();
			session.setAttribute("root", newRoot);
			response.getWriter().write("{\"isSuccess\":"+isSuccess+"}");
		}else {
			response.getWriter().write("{\"isSuccess\":"+isSuccess+"}");
		}
	}
}